GBML manual / Maths

int_floor

The largest int not greater than value, rounding toward NEGATIVE INFINITY - 1.9 becomes 1 (same as int_part), but -1.9 becomes -2 (int_part would say -1).

Syntax

int_floor(value) -> int

Arguments

NameType
valuereal

Returns

int

Description

The largest int not greater than value - rounds toward NEGATIVE INFINITY, never toward zero. 3.75 becomes 3 (same as int_part), but -3.75 becomes -4 (int_part would say -3).

Use this whenever the result means "which cell/tile/bucket does this position fall inside." A position inside a room is never negative (the room starts at 0), but a position just past the room's left or top edge can be, and so can an offset such as x - 20 near the edge, so a negative value is not a rare case. int_floor gives the tile a position is actually standing inside on both sides of zero; int_part is one cell short of correct the instant the position goes negative, and the mistake is easy to miss, because it does not show up until something crosses the axis.

floor rounds the same way but hands back a real - use it when the result goes straight back into real maths and does not have to be an int.

For "which of several discrete values is this closest to" rather than "which cell contains it," see int_round instead - it rounds to the NEAREST whole number, not down.

Example

var tile_size = 8;
var tile_col = int_floor(x / tile_size);
var tile_row = int_floor(y / tile_size);

Works the same on both sides of zero: a position at x = -1 (just past the room's left edge) lands in tile column -1, not column 0 - int_part(-1 / 8) would wrongly say 0, the SAME column as a position at x = 1.

On the GBA

This is what "which grid cell/tile is this world position in" needs, and what the engine itself uses for exactly that. A position just past a room’s left or top edge (or an offset such as x - 20 near the edge) is negative, so that is never an edge case - reach for int_floor, not int_part, whenever the result means "which cell."

See also: floorint_partint_roundint_ceil